﻿@section header{

}
<div class="topPanel" style="border: 0px;">
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;">
                        <span class="input-group-btn">
                            <button type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新建按钮</a>
            <a class="btn btn-primary" onclick="btn_clonebutton()"><i class="fa fa-plus"></i>新建常用按钮</a>
        </div>
        <div class="operate">
            <ul class="nav nav-pills">
                <li class="first">已选中<span>1</span>项</li>
                <li><a onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改按钮</a></li>
                <li><a onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除按钮</a></li>
                <li><a onclick="btn_details()"><i class="fa fa-search-plus"></i>查看按钮</a></li>
            </ul>
            <a href="javascript:;" class="close"></a>
        </div>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <style>
        .ui-jqgrid {
            border-left: 0px;
            border-right: 0px;
            border-bottom: 0px;
        }
    </style>
</div>
@section scripts{
    <script>
        var baseUrl = "/rbac/MenuElement/";
        var moduleId = $.request("moduleId");
        $(function () {
            gridList();
        })
        function gridList() {
            $("#gridList").dataGrid({
                url: baseUrl+"GetListByModuleId?moduleId=" + moduleId,
                mtype: "POST",
                height: $(window).height() - 90,
                colModel: [
                    { label: "主键", name: "ID", hidden: true, key: true },
                    {
                        label: '排序', name: 'OrderBy', width: 100, align: 'left',
                        formatter: function (cellvalue, options, rowObject) {
                            var keyId = rowObject.ID;
                            return "<input type='text' name='OrderBy[" + keyId + "]' autocomplete='off' style='width: 50px; height: 20px;' onchange='update_field(\"" + keyId + "\",this.value)' value=" + cellvalue + " />";
                        }
                    },
                    { label: '按钮ID', name: 'DomId', width: 150, align: 'left' },
                    { label: '按钮名称', name: 'Name', width: 150, align: 'left' },
                    { label: '按钮连接', name: 'Script', width: 270, align: 'left' },
                ],
                rowNum: 20,
                rowList: [20, 50, 100],
                pager: '#gridPager',
                sortname: 'OrderBy',
                sortorder: "asc",
                viewrecords: true,
                autowidth: true,
                multiselect: true,
                loadComplete: function () {
                    $('.ui-jqgrid-bdiv').scrollTop(0);
                    setTimeout(function () { btn_tc(); });
                }
            });
        }
        function btn_add() {
            $.modalOpen({
                id: "Form",
                title: "新增按钮",
                url: baseUrl +"Form?moduleId=" + moduleId,
                width: "700px",
                height: "440px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_edit() {
            var keyValue = $("#gridList").jqGridRowValue().ID;
            $.modalOpen({
                id: "Form",
                title: "修改按钮",
                url: baseUrl +"Form?moduleId=" + moduleId + "&keyValue=" + keyValue,
                width: "700px",
                height: "440px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
        function btn_delete() {
            $.deleteForm({
                url: baseUrl +"DeleteForm",
                param: { keyValue: $("#gridList").jqGridRowValue().ID },
                success: function () {
                    $("#gridList").resetSelection();
                    $("#gridList").trigger("reloadGrid");
                }
            })
        }
        function btn_details() {
            var keyValue = $("#gridList").jqGridRowValue().ID;
            $.modalOpen({
                id: "Details",
                title: "查看按钮",
                url: baseUrl +"Details?moduleId=" + moduleId + "&keyValue=" + keyValue,
                width: "700px",
                height: "490px",
                btn: null,
            });
        }
        function btn_clonebutton() {
            $.modalOpen({
                id: "CloneButton",
                title: "克隆按钮",
                url: "/SystemManage/ModuleButton/CloneButton?moduleId=" + moduleId,
                width: "400px",
                height: "600px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            $.ajax({
                url: baseUrl +"CloneButton?moduleId=" + moduleId,
                success: function (data) {
                    if (data.result > 0) {
                        layui.layer.msg("操作成功", { icon: 1, time: 2000 });
                        $("#gridList").trigger("reloadGrid");
                    }
                    else {
                        layui.layer.msg("操作失败", { icon: 2, time: 2000 });
                    }
                },
                error: function () {
                    layui.layer.msg("操作失败", { icon: 2, time: 2000 });
                }
            });

        }
        function update_field(keyId, cellvalue) {
            $.ajax({
                url: baseUrl + "UpdateOrderBy?keyId=" + keyId + "&value=" + cellvalue,
                data: {},
                dataType: "json",
                type: "POST",
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }
    </script>
}